# -*- coding=utf-8 -*-

"""
index model
"""

from framework.mongo import MongoModel
import pymongo

class IndexModel(MongoModel):
    """index data model"""

    def __init__(self):
        """must call super init to connection db"""
        super(IndexModel, self).__init__()

    def return_coll(self):
        """return databae name and collection name"""
        return 'fuwa', 'view'

    def get_two_count(self):
        """get last two day count"""
        # return self.collection.find(sort=[('sync_time', pymongo.DESCENDING)])[0: 2]
        return self.find(sort=[('sync_time', pymongo.DESCENDING)])[0:2]

    def get_fuwa(self, start, size=50):
        """total fuwa id number for every day"""
        count = self.count()
        if start > count:
            return
        # end = start + size - 1
        end = start + size
        return self.find(sort=[('sync_time', pymongo.DESCENDING)])[start: end]
